<?PHP
 require_once('inc/int.php');

 if (!isset($_GET['page']) || !preg_match('(^[a-zA-Z\.0-9]+$)', $_GET['page'])
     || !file_exists('documentation/' . LANG . '/' . $_GET['page'] . '.html')) {
  require('404.html');
  return;
 }

 $data = file('documentation/' . LANG . '/' . $_GET['page'] . '.html');

 $title = array_shift($data);

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
 <head>
  <title>DMDirc :: Documentation :: <?PHP echo $title; ?></title>
  <link rel="stylesheet" type="text/css" href="../res/style.css">
  <link rel="icon" type="image/png" href="../res/favicon.png">
 </head>
 <body>
  <div id="container" class="docs">
   <img id="logo" src="../res/logo.png" alt="DMDirc logo">
   <h1>DMDirc</h1>
<?PHP define('SUBPAGE', $_GET['page']); define('PAGE', 'docs'); define('PREFIX', '../'); require_once('inc/menu.php'); ?>
    <div class="left">
<?PHP echo implode('', $data); ?>
    </div>
    <div class="right">
     <h2>Documentation</h2>
     <h3>In this section</h3>
     <ul>
<?PHP
 $files = glob('documentation/' . LANG . '/' . preg_replace('/^(.*)\..*?$/', '\1.*', $_GET['page']));
 $found = false;

 foreach ($files as $file) {
  $name = basename($file, '.html');
  $dname = ucwords(preg_replace('#(?<![0-9])\.|\.(?![0-9])#', ' &rarr; ', htmlentities($name)));
  echo '<li><a href="', htmlentities($name), '">', $dname, '</a></li>';
  $found = true;
 }

 if (!$found) { echo '<li><em>No other items in this section</em></li>'; }
?>
     </ul>
     <h3>Other sections</h3>
     <ul>
      <li><em>No other sections available</em></li>
     </ul>
     <h2 class="extra">Problems?</h2>
     <p>
      If you're having problems with DMDirc, please feel free to
      <a href="irc://irc.quakenet.org/DMDirc">join us on IRC</a>.
     </p>
    </div>
   <div id="footer">
   </div>
  </div>
 </body>
</html>
